import request from '@/utils/request'

/**
 * 获取激活码列表
 * @param {Object} params - 查询参数
 * @returns {Promise}
 */
export function getActivationCodeList(params) {
  const queryParams = { ...params };
  
  if (queryParams.usage_count !== undefined && queryParams.usage_count !== '') {
    queryParams.usage_count = Number(queryParams.usage_count);
  }
  
  return request({
    url: '/admin/activation-codes',
    method: 'get',
    params: queryParams
  })
}

/**
 * 获取激活码详情
 * @param {Number} codeId - 激活码ID
 * @returns {Promise}
 */
export function getActivationCodeDetail(codeId) {
  return request({
    url: `/admin/activation-codes/${codeId}`,
    method: 'get'
  })
}

/**
 * 生成激活码
 * @param {Object} data - 生成参数
 * @returns {Promise}
 */
export function generateActivationCode(data) {
  return request({
    url: '/admin/activation-codes/generate',
    method: 'post',
    data
  })
}

/**
 * 获取激活码统计信息
 * @param {Object} params - 查询参数
 * @returns {Promise}
 */
export function getActivationCodeStats(params) {
  return request({
    url: '/admin/activation-codes/stats',
    method: 'get',
    params
  })
}

/**
 * 获取要导出的激活码列表
 * @param {Object} params - 查询参数
 * @returns {Promise}
 */
export function getActivationCodesToExport(params) {
  return request({
    url: '/admin/activation-codes/export',
    method: 'get',
    params
  })
}

/**
 * 删除激活码
 * @param {Number} codeId - 激活码ID
 * @returns {Promise}
 */
export function deleteActivationCode(codeId) {
  return request({
    url: `/admin/activation-codes/delete/${codeId}`,
    method: 'post'
  })
}

/**
 * 标记激活码为已复制
 * @param {Number} codeId - 激活码ID
 * @returns {Promise}
 */
export function markActivationCodeCopied(codeId) {
  return request({
    url: `/admin/activation-codes/mark-copied/${codeId}`,
    method: 'post'
  })
}

/**
 * 标记激活码为已导出
 * @param {Number} codeId - 激活码ID
 * @returns {Promise}
 */
export function markActivationCodeExported(codeId) {
  return request({
    url: `/admin/activation-codes/mark-exported/${codeId}`,
    method: 'post'
  })
}

/**
 * 批量标记激活码为已复制
 * @param {Array} codeIds - 激活码ID数组
 * @returns {Promise}
 */
export function batchMarkActivationCodesCopied(codeIds) {
  return request({
    url: '/admin/activation-codes/batch-mark-copied',
    method: 'post',
    data: { code_ids: codeIds }
  })
}

/**
 * 批量标记激活码为已导出
 * @param {Array} codeIds - 激活码ID数组
 * @returns {Promise}
 */
export function batchMarkActivationCodesExported(codeIds) {
  return request({
    url: '/admin/activation-codes/batch-mark-exported',
    method: 'post',
    data: { code_ids: codeIds }
  })
} 